package org.soarsky.wealthchengdu.junit;

import java.util.List;

import org.soarsky.wealthchengdu.entity.CommentData;
import org.soarsky.wealthchengdu.entity.CommentResultMsg;
import org.soarsky.wealthchengdu.entity.FocusData;
import org.soarsky.wealthchengdu.entity.JsonResult;
import org.soarsky.wealthchengdu.entity.LogonResult;
import org.soarsky.wealthchengdu.entity.NewsContentData;
import org.soarsky.wealthchengdu.entity.NewsData;
import org.soarsky.wealthchengdu.entity.NewsResultMsg;
import org.soarsky.wealthchengdu.entity.WeatherData;
import org.soarsky.wealthchengdu.network.FGFWebService;
import org.soarsky.wealthchengdu.network.ParserResults;




import android.test.AndroidTestCase;

public class ParserResultsJUnit extends AndroidTestCase{
	private FGFWebService service;
	@Override
	protected void setUp() throws Exception {
		// TODO Auto-generated method stub
		service = new ParserResults();
		getLogon();
	}
	private static void error(JsonResult<?> jsonResult){
		System.out.println("错误码:"+jsonResult.getCode()+"===错误信息:"+jsonResult.getMsg());
	}
	// 登录
	private void getLogon() {
		try {
			JsonResult<LogonResult> jsonResult = service.authLogon("张三");
			if (jsonResult != null) {
				if (jsonResult.isError()) {
					System.out.println(jsonResult.getMsg() + "==="
							+ jsonResult.getCode()+"===");
				} else {
					System.out
							.println(jsonResult.getData().getUserId() + "==="+jsonResult.getData().getNickName());
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString() + "===");
		}
	}

	//登出
	public void authLogout(){
		try {
			JsonResult<LogonResult> jsonResult = service.authLogout();
			if(!jsonResult.isError()){
				System.out.println("是否登出="+jsonResult.getData().isLogoutResult());
			}else if(jsonResult!=null){
				error(jsonResult);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println("authLogout="+e.toString());
		}
	}
	//修改名称
	public void updNickName(){
		try {
			JsonResult<Boolean> jsonResult=service.updNickName("李八");
			if (jsonResult.isError()) {
				System.out.println(jsonResult.getMsg() + "==="
						+ jsonResult.getCode()+"===");
			} 
			else
				System.out.println("是否修改成功="+jsonResult.getData());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
	//5.4	焦点图服务(F
	public void getFocus() {
		try {
			JsonResult<List<FocusData>> result = service.getFocus("0");
			if (result != null && !result.isError()) {
				FocusData data = result.getData().get(0);
				System.out.println(data.getName());
				System.out.println(data.getImg());
			}else if(result!=null){
				error(result);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
	//	新闻服务(News Service) 
	public void getNews(){
		try {
			JsonResult<NewsResultMsg> result=service.getNews("1", "1");
			if(result==null)
				return; 
			if(result.isError()){
				error(result);
			}else{
				NewsResultMsg dataMsg = result.getData();
				NewsData data = dataMsg.getData().get(0);
				System.out.println(dataMsg.getData().size()+"===="+data.getId());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
	// 5.5.2	获取新闻内容
	public void getNewsContent(){
		try {
			JsonResult<NewsContentData> result=service.getNewsContent("15");
			if(result==null)
				return;
			if(result.isError()){
				error(result);
			}else{
				NewsContentData dataMsg = result.getData();
				System.out.println(dataMsg.getId()+"==id");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
	//5.5	新闻服务(News Service) 
	 // 5.6.1	获取评论内容
	public void getComment(){
		try {
			JsonResult<CommentResultMsg> result=service.getComment("15", "10", "1");
			if(result==null)
				return;
			if(result.isError()){
				error(result);
			}else{
				CommentResultMsg dataMsg = result.getData();
				CommentData data = dataMsg.getData().get(0);
				System.out.println(dataMsg.getData().size()+"===="+data.getId());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
	//5.6.2	评论文章	
	public void sendComment(){
		try {
			JsonResult<String> result=service.sendComment("15","我发表了评论123");
			if(result==null)
				return;
			if(result.isError()){
				error(result);
			}else{
				String str=result.getData();
				System.out.println(str+"====");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
	// 5.7.1	文章“赞一个”	
	public void sendVote(){
		try {
			JsonResult<String> result=service.sendVote("15");
			if(result==null)
				return;
			if(result.isError()){
				error(result);
			}else{
				String str=result.getData();
				System.out.println(str+"====");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
	//5.8.1	文章分享成功通知
	public void sendShare(){
		try {
			JsonResult<String> result=service.sendShare("15");
			if(result==null)
				return;
			if(result.isError()){
				error(result);
			}else{
				String str=result.getData();
				System.out.println(str+"====222");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
	
	// 5.9.1	文章收藏成功通知
	public void sendCollect(){
		try {
			JsonResult<String> result=service.sendCollect("15");
			if(result==null)
				return;
			if(result.isError()){
				error(result);
			}else{
				String str=result.getData();
				System.out.println(str+"====222");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
	
	//5.10	天气服务(Weather Service) 
	public void getWeather(){
		try {
			JsonResult<WeatherData> result=service.getWeather("0");
			if(result==null)
				return;
			if(result.isError()){
				error(result);
			}else{
				WeatherData data = result.getData();
				System.out.println(data.getCity()+"===");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
		}
	}
}
